package com.share;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;

/**
 * author:caifan
 * date:2019/9/21
 */
@SpringBootApplication
@PropertySource(value = {"classpath:application.yml"})
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    /**
     * uri中的url为要获取的请求url，如route_02中localhost:8100/rest  会请求localhost:7777/rest
     * @param builder
     * @return
     */
    @Bean
    public RouteLocator myRoutes(RouteLocatorBuilder builder) {
        return builder.routes().route("route_01", p -> p.path("/get")
                .filters(f -> f.addRequestHeader("hello", "java"))
                .uri("https://gitee.com/")
                ).route("route_02", p -> p.path("/**")
                .uri("http://localhost:7777"))
                .build();
    }
}
